<template>
  <div class="componentBox">
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="商品名称"
        label="商品名称"
        placeholder="输入商品名称"
        :rules="[{ required: true, message: '请填写商品名称' }]"
      />
      <van-button block type="info" native-type="submit">提交</van-button>
    </van-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: ""
    };
  },
  methods: {
    async onSubmit() {
      const { data: res } = await this.$http.post( `api/addproduct`, { name: this.username });
      if (res.status != 0)
        return this.$notify({ type: "danger", message: "添加失败" });
      this.$notify({ type: "success", message: "添加成功" });
      this.username = "";
    }
  }
};
</script>

<style lang="less" scoped>
.van-nav-bar {
  background: #1989fa;
  height: 50px;
  line-height: 50px;
  &__title,
  &__text,
  &__arrow {
    color: #fff !important;
  }
}
.van-field {
  border-bottom: 1px solid #eee;
}
.van-button {
  width: 90%;
  margin: 10px auto;
  display: block;
}
</style>